package com.wuhan.template.module.home.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.display.RoundedBitmapDisplayer;
import com.wuhan.template.R;
import com.wuhan.template.base.BaseApplication;
import com.wuhan.template.module.home.entity.ActivityInfoEntity;

import java.util.List;

/**
 * Created by Administrator on 2016/5/10 0010.
 */
public class HouDongRecyclerAdapter extends RecyclerView.Adapter<HouDongRecyclerAdapter.MyViewHolder>{

    private Context context;
    private  List<ActivityInfoEntity.ListBean> list;
    private LayoutInflater inflater;
    private ImageLoader loader;
    private DisplayImageOptions options;

    public HouDongRecyclerAdapter(Context context, List<ActivityInfoEntity.ListBean> list) {
        this.context = context;
        this.list = list;
        inflater = LayoutInflater.from(context);
        loader = ((BaseApplication)(context.getApplicationContext())).getImageLoader();
        options = new DisplayImageOptions.Builder()
                .cacheOnDisk(true)
                .cacheOnDisk(true)
                .showImageOnFail(R.mipmap.app_logo)
                .displayer(new RoundedBitmapDisplayer(15))
                .build();
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = inflater.inflate(R.layout.huodong_list_item, null);
        MyViewHolder holder = new MyViewHolder(view);
        holder.title= (TextView) view.findViewById(R.id.activity_info_title);
        holder.count= (TextView) view.findViewById(R.id.activity_info_count);
        holder.imageInfo = (ImageView) view.findViewById(R.id.activity_imageInfo);
        return holder;
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {

        holder.title.setText(list.get(position).getTitle());
        holder.count.setText(list.get(position).getComment_num());
        ActivityInfoEntity.ListBean.IndexpicBean indexpic = list.get(position).getIndexpic();
        String imageUrl = indexpic.getHost()+ indexpic.getDir()+ indexpic.getFilepath()+ indexpic.getFilename();
        holder.imageInfo.setScaleType(ImageView.ScaleType.FIT_XY);
        loader.displayImage(imageUrl,holder.imageInfo,options);

    }

    @Override
    public int getItemCount() {
        return 0;
    }

    public static class MyViewHolder extends RecyclerView.ViewHolder{

        public MyViewHolder(View itemView) {
            super(itemView);
        }

        TextView title;
        TextView count;
        ImageView imageInfo;
    }
}
